<template>
  <div class="app-container">
      <div class="bodyBox">

          <!-- 总人数：200     编内：50  合同：50  劳务派遣：50  退休：50  离休：50 -->

          <el-row :gutter="10" class="mb8">
              <el-col :span="1.5" class="numTitle">
                  总人数：{{ statistics.allNumber }}人
              </el-col>
              <el-col :span="1.5" class="numTitle">
                  编内：{{ statistics.dispatchNum }}人
              </el-col>
              <el-col :span="1.5" class="numTitle">
                  合同：{{ statistics.contractNum }}人
              </el-col>
              <el-col :span="1.5" class="numTitle">
                  劳务派遣：{{ statistics.organizationNum }}人
              </el-col>
              <el-col :span="1.5" class="numTitle">
                  退休：{{ statistics.retireNum }}人
              </el-col>
              <el-col :span="1.5" class="numTitle">
                  离休：{{ statistics.retirementNum }}人
              </el-col>
          </el-row>
          <!-- 条件筛选 -->
          <el-form :model="queryParams" ref="queryForm" :inline="true" size="mini" v-show="showSearch"
              label-width="100px">
              <el-form-item label="所属机构" prop="institutionId">
                  <el-select v-model="queryParams.institutionId" placeholder="请选择所属机构" @change="deptChangeQuery">
                      <el-option v-for="(dict, index) in deparmentList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="所属部门" prop="departmentId">
                  <el-select v-model="queryParams.departmentId" placeholder="请选择所属部门"
                      :disabled="!bumenQueryList || bumenQueryList.length == 0" @change="bumenChangeQuery">
                      <el-option v-for="(dict, index) in bumenQueryList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="所属科室" prop="postId">
                  <el-select v-model="queryParams.postId" placeholder="请选择所属科室"
                      :disabled="!keshiQueryList || keshiQueryList.length == 0" @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in keshiQueryList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="人员身份" prop="identityValue">
                  <el-select v-model="queryParams.identityValue" placeholder="请选择人员身份"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in identityList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="员工姓名" prop="employeeName">
                  <el-input v-model="queryParams.employeeName" placeholder="请输入员工姓名"
                      @keyup.enter.native="handleQuery" />
              </el-form-item>

              <el-form-item label="人员状态" prop="peopleState">
                  <el-select v-model="queryParams.peopleState" no-match-text="请选择人员状态" placeholder="请选择人员状态"
                      @keyup.enter.native="handleQuery">
                      <!-- @change="onStateChange" -->
                      <el-option v-for="(dict, index) in stateDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="认定职务" prop="peopleDutiesName">
                  <el-select v-model="queryParams.peopleDutiesName" placeholder="请选择认定职务" style="width: 100%"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in dutiesListRD" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="职级" prop="peopleRankName">
                  <el-select v-model="queryParams.peopleRankName" placeholder="请选择职级" style="width: 100%"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in rankListRD" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="岗位级别" prop="employLevel">
                  <el-select v-model="queryParams.employLevel" placeholder="请选择岗位等级" style="width: 100%"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(item, index) in gangweiList" :key="index" :label="item.name"
                          :value="item.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="从事专业" prop="engagingProfession">
                  <el-select v-model="queryParams.engagingProfession" placeholder="请选择从事专业"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in engagingList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="政治面貌" prop="politicalOutlook">
                  <el-select v-model="queryParams.politicalOutlook" placeholder="请选择政治面貌"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in politicalDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="学历" prop="formalSchooling">
                  <el-select v-model="queryParams.formalSchooling" placeholder="请选择学历"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in eduList" :key="index" :label="dict.name" :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="学习形式" prop="learningForms">
                  <el-select v-model="queryParams.learningForms" placeholder="请选择学历"
                      @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in studyMethodList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <!-- 暂时隐藏 -->
              <!-- 
              <el-form-item label="信息完善度" prop="Information_completeness">
                  <el-select v-model="queryParams.Information_completeness" placeholder="请选择信息完善度范围" @keyup.enter.native="handleQuery">
                      <el-option v-for="(dict, index) in InformationList" :key="index" :label="dict.label"
                          :value="dict.value" />
                  </el-select>
              </el-form-item> -->

              <el-form-item>
                  <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
              </el-form-item>
          </el-form>
          <el-row :gutter="10" class="mb8">
              <!-- 
                  <el-col :span="1.5">
                  <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                      v-if="buttons.includes('add')">新增
                  </el-button>
                  </el-col> -->

              <el-col :span="1.5">
                  <!-- <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                          v-if="buttons.includes('export')">导出
                      </el-button> -->

                  <el-button type="warning" plain icon="el-icon-download" size="mini"
                      @click="dialogVisible = true">导出</el-button>

              </el-col>
              <el-col :span="1.5">
                  <el-button type="success" plain icon="el-icon-download" size="mini"
                      @click="handleDownDeptTemplate">下载模板
                      <!-- v-if="buttons.includes('down_template')" -->
                  </el-button>
              </el-col>
              <el-col :span="1.5">
                  <el-upload class="upload-demo" :action="fileUploadUrl" name="filename" :limit="1"
                      :on-success="onUpSuccess" :headers="headers" :file-list="fileList" :show-file-list="false">
                      <!-- v-if="buttons.includes('import')" -->
                      <el-button icon="el-icon-upload2" size="mini" plain type="default">导入数据</el-button>
                  </el-upload>

              </el-col>
              <!-- 新增 icon="el-icon-setting"-->
              <el-col :span="1.5">
                  <el-button type="primary" plain  size="mini" icon="el-icon-setting"
                      @click="showSetTable = true">设置表头
                  </el-button>
              </el-col>
              <!-- 
        <el-col :span="1.5">
          <el-button
            type="default"
            plain
            icon="el-icon-postcard"
            size="mini"
            @click="handleSendMsg"
            v-if="buttons.includes('send_msg')"
            >发送消息
          </el-button>
        </el-col> -->

              <right-toolbar @queryTable="getList"></right-toolbar>
          </el-row> 
         
          <el-table v-loading="loading" :data="employeeList" style="width: 100%" border @selection-change="handleSelectionChange" >
              <template>
                  <el-table-column label="员工编号" align="center" prop="number" min-width="120px" fixed="left" />
                  <el-table-column label="员工姓名" align="left" prop="employeeName" width="120" fixed="left" >
                      <template slot-scope="scope">
                          <el-link type="primary" @click="handleDetail(scope.row)"><i class="el-icon-user"></i>
                              {{ scope.row.employeeName }}
                          </el-link>
                      </template>
                  </el-table-column>
                  <el-table-column v-for="(header,index) in TableHeaders" 
                  :key="header.id"
                  :prop="header.parameterName"
                  :label="header.parameterNote"
                  align="center" min-width="165px" show-overflow-tooltip>
                  <template slot-scope="scope" v-show="showColumn(header.parameterName)">
                      <span>{{
                          parseTime(scope.row[header.parameterName], "{y}-{m}-{d}")
                      }}</span>
                  </template>
                  <template slot-scope="scope"> {{ scope.row[header.parameterName] }}</template>
                  
                  </el-table-column>

                 
              </template>
              <el-table-column label="操作" fixed="right" width="90" align="center">
                  <template slot-scope="scope">
                      <!-- <el-button
              size="mini"
              type="text"
              @click="handleAdjust(scope.row)"
              v-if="buttons.includes('adjust')"
              >岗位变动
            </el-button> -->
                      <el-button :loading="buttonLoading" size="mini" type="text" @click="handlePassword(scope.row)"
                          v-if="buttons.includes('resetPasswordNew')">
                          修改密码
                      </el-button>
                      <!-- <el-button
              size="mini"
              type="text"
              @click="handleUpdate(scope.row)"
              v-if="buttons.includes('edit')"
              >修改
            </el-button> -->
                  </template>
              </el-table-column>
          </el-table>

          <div class="block" style="text-align: right">
              <!-- <el-config-provider :locale="$commonLang('customPagination')"> -->
              <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                  :current-page="queryParams.pageNum" background :page-sizes="[10, 20, 30, 50]"
                  :page-size="queryParams.pageSize" layout="slot, sizes, prev, pager, next, jumper" :total="total">
                  <span class="totalPeople">共 {{ total }} 人</span>
              </el-pagination>
              <!-- </el-config-provider> -->
          </div>
      </div>

      <!-- 添加或修改员工对话框 -->
      <el-dialog :title="title" :visible.sync="open" append-to-body @close="cancel" width="50%">
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
              <el-divider content-position="center">账号信息</el-divider>
              <el-form-item label="姓名" prop="employeeName">
                  <el-input v-model="form.employeeName" placeholder="请输入员工姓名" />
              </el-form-item>
              <el-divider content-position="center">岗位信息</el-divider>
              <el-form-item label="所属机构" prop="institutionId">
                  <el-select v-model="form.institutionId" placeholder="请选择所属机构" style="width: 100%" clearable
                      @change="departmentChange">
                      <el-option v-for="(dict, index) in deparmentList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="所属部门" prop="departmentId">
                  <el-select v-model="form.departmentId" placeholder="请选择所属部门" style="width: 100%"
                      :disabled="!bumenList || bumenList.length == 0" clearable @change="bumenChange">
                      <el-option v-for="(dict, index) in bumenList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="所属科室" prop="postId">
                  <el-select v-model="form.postId" placeholder="请选择所属科室" style="width: 100%"
                      :disabled="!keshiList || keshiList.length == 0" clearable>
                      <el-option v-for="(dict, index) in keshiList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="角色" prop="employeeRole">
                  <el-select v-model="form.employeeRole" placeholder="请选择角色" style="width: 100%" clearable>
                      <el-option v-for="(dict, index) in jobList" :key="index" :label="dict.name" :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="从事专业" prop="engagingProfession">
                  <el-select v-model="form.engagingProfession" placeholder="请选择从事专业" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in engagingList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="专业类别" prop="majorType">
                  <el-select v-model="form.majorType" placeholder="请选择专业类别" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in majorTypeList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="人员状态" prop="peopleState">
                  <el-select v-model="form.peopleState" no-match-text="请选择人员状态" placeholder="请选择人员状态" clearable
                      style="width: 100%">
                      <el-option v-for="(dict, index) in stateDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="人员身份" prop="identityValue">
                  <el-select v-model="form.identityValue" placeholder="请选择人员身份" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in identityList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
              <el-form-item label="身份证号" prop="idCard">
                  <el-input v-model="form.idCard" placeholder="请输入身份证号" />
              </el-form-item>

              <el-form-item label="生日" prop="employeeBirthday">
                  <el-date-picker clearable style="width: 100%" v-model="form.employeeBirthday" type="date"
                      :editable="false" value-format="yyyy-MM-dd HH:mm:ss" placeholder="输入身份证号自动生成" disabled>
                      <!-- <el-input
          v-model="form.employeeBirthday"
          placeholder="输入身份证号自动生成"
          disabled
        /> -->
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="性别" prop="employeeSex">
                  <!-- <el-input
          v-model="form.employeeSex"
          placeholder="输入身份证号自动生成"
          disabled
        /> -->
                  <el-select v-model="form.employeeSex" placeholder="输入身份证号自动生成" clearable disabled
                      style="width: 100%">
                      <el-option v-for="(dict, index) in genderList" :key="index" :label="dict.name"
                          :value="parseInt(dict.id)" />
                  </el-select>
              </el-form-item>

              <el-form-item label="籍贯" prop="hometown">
                  <!-- <el-input v-model="form.hometown" placeholder="请输入籍贯" /> -->
                  <el-cascader placeholder="选择籍贯" :props="props" v-model="form.hometown" @change="homeChange"
                      clearable style="width: 100%"></el-cascader>
              </el-form-item>

              <el-form-item label="民族" prop="nation">
                  <el-select v-model="form.nation" placeholder="请选择民族" style="width: 100%" clearable>
                      <el-option v-for="(dict, index) in nationDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="学历" prop="formalSchooling">
                  <el-select v-model="form.formalSchooling" placeholder="请选择学历" style="width: 100%">
                      <el-option v-for="(dict, index) in eduList" :key="index" :label="dict.name"
                          :value="parseInt(dict.id)" />
                  </el-select>
              </el-form-item>
              <el-form-item label="毕业学校" prop="school">
                  <el-input v-model="form.school" placeholder="请输入毕业学校" />
              </el-form-item>
              <el-form-item label="所学专业" prop="speciality">
                  <el-input v-model="form.speciality" placeholder="请输入所学专业" />
              </el-form-item>

              <!-- <el-form-item label="学习时间" prop="studyTime">
        <el-date-picker
          clearable
          style="width: 100%"
          v-model="form.studyTime"
          type="date"
          :editable="false"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择学习时间"
        >
        </el-date-picker>
      </el-form-item> -->

              <el-form-item label="毕业时间" prop="graduation">
                  <el-date-picker clearable style="width: 100%" v-model="form.graduation" type="date"
                      :editable="false" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择毕业时间">
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="学位" prop="academicDegree">
                  <el-input v-model="form.academicDegree" placeholder="请输入学位" />
              </el-form-item>

              <!-- <el-form-item label="手机号" prop="phone">
        <el-input v-model="form.phone" placeholder="请输入手机号" />
      </el-form-item> -->

              <!-- <el-form-item label="毕业学校" prop="school">
        <el-input v-model="form.school" placeholder="请输入毕业学校" />
      </el-form-item>

      <el-form-item label="专业" prop="major">
        <el-input v-model="form.major" placeholder="请输入专业" />
      </el-form-item> -->

              <!-- <el-form-item label="毕业时间" prop="graduationTime">
        <el-date-picker
          clearable
          style="width: 100%"
          v-model="form.graduationTime"
          type="date"
          :editable="false"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择毕业时间"
        >
        </el-date-picker>
      </el-form-item> -->

              <!-- <el-form-item label="工作时间" prop="employmentTime">
        <el-date-picker
          clearable
          style="width: 100%"
          v-model="form.employmentTime"
          type="date"
          :editable="false"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择工作时间"
        >
        </el-date-picker>
      </el-form-item> -->

              <!--        <el-form-item label="账号" prop="accountNumber">-->
              <!--          <el-input v-model="form.accountNumber" placeholder="请输入账号"/>-->
              <!--        </el-form-item>-->
              <!--        <el-form-item label="密码" prop="accountPassword">-->
              <!--          <el-input v-model="form.accountPassword" placeholder="请输入密码"/>-->
              <!--        </el-form-item>-->

              <el-form-item label="人员类型" prop="type">
                  <el-select v-model="form.type" placeholder="请选择人员类型" style="width: 100%">
                      <el-option v-for="(dict, index) in employeeTypeDict" :key="index" :label="dict.name"
                          :value="parseInt(dict.id)" />
                  </el-select>
              </el-form-item>

              <el-form-item label="邮箱" prop="email">
                  <el-input v-model="form.email" placeholder="请输入邮箱" />
              </el-form-item>
              <!-- <el-form-item label="身份证" prop="idCard">
        <el-input v-model="form.idCard" placeholder="请输入身份证" />
      </el-form-item> -->
              <el-form-item label="政治面貌" prop="politicalOutlook">
                  <el-select v-model="form.politicalOutlook" placeholder="请选择政治面貌" style="width: 100%" clearable>
                      <el-option v-for="(dict, index) in politicalDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="加入组织时间" prop="joinOrganizationTime" v-if="form.politicalOutlook != 50">
                  <el-date-picker clearable style="width: 100%" v-model="form.joinOrganizationTime" type="date"
                      :editable="false" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择加入组织时间">
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="手机号1" prop="phone">
                  <el-input v-model="form.phone" placeholder="请输入手机号" />
              </el-form-item>
              <el-form-item label="手机号2" prop="phone1">
                  <el-input v-model="form.phone1" placeholder="请输入手机号" />
              </el-form-item>

              <el-form-item label="从业经验(年)" prop="employmentDate">
                  <el-input clearable v-model="form.employmentDate" placeholder="请选择从业时间">
                  </el-input>
              </el-form-item>

              <el-form-item label="来院时间" prop="toHospitalTime">
                  <el-date-picker clearable style="width: 100%" v-model="form.toHospitalTime" type="date"
                      :editable="false" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择来院时间">
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="入职时间" prop="entryTime">
                  <el-date-picker clearable style="width: 100%" v-model="form.entryTime" type="date" :editable="false"
                      value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择入职时间">
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="工作时间" prop="employmentTime">
                  <el-date-picker clearable style="width: 100%" v-model="form.employmentTime" type="date"
                      :editable="false" value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择工作时间">
                  </el-date-picker>
              </el-form-item>

              <el-form-item label="入职方式" prop="entryMethod">
                  <el-select v-model="form.entryMethod" placeholder="请选择入职方式" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in entryMethodList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="学习方式" prop="learningForms">
                  <el-select v-model="form.learningForms" placeholder="请选择学习方式" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in studyMethodList" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="绩效分类" prop="performanceType">
                  <el-select v-model="form.performanceType" placeholder="请选择绩效分类" clearable style="width: 100%">
                      <el-option v-for="(dict, index) in JXList" :key="index" :label="dict.name" :value="dict.id" />
                  </el-select>
              </el-form-item>

              <!-- <el-form-item label="编制" prop="organization">
        <el-select
          v-model="form.organization"
          placeholder="请选择编制类型"
          style="width: 100%"
          clearable
        >
          <el-option
            v-for="(dict, index) in organizationTypeConfig"
            :key="index"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->

              <!-- <el-form-item label="职级" prop="peopleRank">
        <el-select
          v-model.number="form.peopleRank"
          placeholder="请选择职级"
          style="width: 100%"
        >
          <el-option
            v-for="item in rankList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item> -->

              <el-form-item label="残疾状况" prop="physicalDisability">
                  <el-select v-model="form.physicalDisability" placeholder="请选择残疾状况" style="width: 100%" clearable>
                      <el-option v-for="(dict, index) in disabilityTypeConfig" :key="index" :label="dict.label"
                          :value="dict.value" />
                  </el-select>
              </el-form-item>

              <el-form-item label="头像" prop="img">
                  <el-upload class="avatar-uploader" :action="fileUploadUrl" :show-file-list="false"
                      :on-success="handleAvatarSuccess" name="filename" :accept="'image/*'">
                      <img v-if="avatarImg" :src="avatarImg" class="avatar" />
                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                      <div slot="tip" class="el-upload__tip">
                          只能上传图片文件，且不超过10MB
                      </div>
                  </el-upload>
              </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
              <el-button @click="cancel">取 消</el-button>
              <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          </div>
      </el-dialog>

      <!--调岗对话框-->
      <el-dialog title="岗位调整" :visible.sync="adjustOpen" width="500px" append-to-body @close="cancelAdjust">
          <el-form :model="adjustForm" ref="adjustForm" :rules="adjustRules" v-show="showSearch" label-width="80px">
              <el-form-item label="所属机构" prop="institutionId">
                  <el-select v-model="adjustForm.institutionId" placeholder="请选择所属机构" clearable style="width: 100%"
                      @change="departmentChange">
                      <el-option v-for="(dict, index) in deparmentList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="所属部门" prop="departmentId">
                  <el-select v-model="adjustForm.departmentId" placeholder="请选择所属部门" style="width: 100%"
                      :disabled="!bumenList || bumenList.length == 0" clearable @change="bumenChange">
                      <el-option v-for="(dict, index) in bumenList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <el-form-item label="所属科室" prop="postId">
                  <el-select v-model.number="adjustForm.postId" placeholder="请选择所属科室" style="width: 100%"
                      :disabled="!keshiList || keshiList.length == 0" clearable>
                      <el-option v-for="(dict, index) in keshiList" :key="index" :label="dict.institutionName"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>

              <!-- <el-form-item label="角色" prop="employeeRole">
        <el-select
          v-model="adjustForm.employeeRole"
          placeholder="请选择角色"
          style="width: 100%"
          clearable
        >
          <el-option
            v-for="(dict, index) in jobList"
            :key="index"
            :label="dict.name"
            :value="dict.id"
          />
        </el-select>
      </el-form-item> -->

              <el-form-item label="调整类型" prop="upType">
                  <el-select v-model="adjustForm.upType" placeholder="请选择调整类型" style="width: 100%" clearable>
                      <el-option v-for="(dict, index) in adjustDict" :key="index" :label="dict.name"
                          :value="dict.id" />
                  </el-select>
              </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
              <el-button @click="cancelAdjust">取 消</el-button>
              <el-button :loading="buttonLoading" type="primary" @click="submitAdjustForm">确 定</el-button>
          </div>
      </el-dialog>

      <!--员工档案弹窗-->
      <el-dialog :title="archiveTitle" :visible.sync="archiveOpen" append-to-body @close="cancelArchive">
          <component :is="archiveComponentName" :employeeId="employeeId"></component>
      </el-dialog>

      <!--发送消息弹窗-->
      <el-dialog title="发送消息" :visible.sync="sendMsgOpen" append-to-body>
          <el-form ref="msgForm" :model="sendMsgForm" :rules="msgRules" label-width="80px" :key="0" size="mini">
              <div class="msgForm">
                  <el-table :data="sendMsgForm.count" :row-key="getRowKey" height="300" border>
                      <el-table-column label="姓名" align="left" prop="employeeName" />
                      <el-table-column label="状态" align="left" prop="stateValue" />
                      <el-table-column label="初步定级" align="left" prop="grading">
                          <template slot-scope="scope">
                              <el-form-item label-width="0" :show-message="false"
                                  :prop="'count.' + scope.$index + '.grading'" :rules="msgRules.grading">
                                  <el-select v-model.number="scope.row.grading" placeholder="请选择初步定级">
                                      <el-option v-for="item in rankList" :key="item.id" :label="item.name"
                                          :value="item.id">
                                      </el-option>
                                  </el-select>
                              </el-form-item>
                          </template>
                      </el-table-column>

                      <el-table-column label="计划到岗时间" align="left" prop="dutyTime" min-width="150px">
                          <template slot-scope="scope">
                              <el-form-item label-width="0" :prop="'count.' + scope.$index + '.dutyTime'"
                                  :rules="msgRules.dutyTime">
                                  <el-date-picker v-model="scope.row.dutyTime" align="right" type="date"
                                      :editable="false" placeholder="选择计划到岗时间" value-format="yyyy-MM-dd">
                                  </el-date-picker>
                              </el-form-item>
                          </template>
                      </el-table-column>
                  </el-table>
              </div>
          </el-form>
          <div slot="footer" class="dialog-footer">
              <el-button plain @click="sendMsgOpen = false">取 消</el-button>

              <el-button :loading="buttonLoading" type="primary" @click="submitSendMsg">
                  发送
              </el-button>
          </div>
      </el-dialog>

      <el-dialog title="修改密码" :visible.sync="openPassword" width="500px" append-to-body>
          <el-form ref="formPassword" :model="formPassword" :rules="rulesPassword" label-width="100px">
              <el-form-item label="新密码" prop="newPassword">
                  <el-input v-model="formPassword.newPassword" :type="passwordAndText" auto-complete="off"
                      placeholder="密码">
                      <svg-icon :icon-class="LookIco" style="cursor: pointer; margin-right: 10px" @click="CanNo"
                          class="el-icon-edit el-input__icon" slot="suffix" />
                  </el-input>
              </el-form-item>
              <el-form-item label="确认密码" prop="newPasswordTo">
                  <el-input v-model="formPassword.newPasswordTo" :type="passwordAndTextTo" auto-complete="off"
                      placeholder="确认密码">
                      <svg-icon :icon-class="LookIcoTo" style="cursor: pointer; margin-right: 10px" @click="CanNoTo"
                          class="el-icon-edit el-input__icon" slot="suffix" />
                  </el-input>
              </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
              <el-button :loading="buttonLoading" type="primary" @click="submitFormPassword">确 定</el-button>
              <el-button @click="openPassword = false">取 消</el-button>
          </div>
      </el-dialog>

      <!-- daochu -->
      <el-dialog title="导出" :visible.sync="dialogVisible" width="30%">

          <el-select v-model="pageType" placeholder="请选择导出模块" size="mini" multiple style="width: 100%;">
              <el-option v-for="item in exportOptions" :key="item.id" :label="item.label" :value="item.id">
              </el-option>
          </el-select>

          <span slot="footer" class="dialog-footer">
              <el-button size="mini" @click="CancleBtn()">取 消</el-button>
              <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出
              </el-button>

          </span>
      </el-dialog>
      <!-- 设置表头 -->
      <el-dialog title="设置表头" :visible.sync="showSetTable" width="60%" class="setTableC">
          <!-- <el-divider style="margin:0px"></el-divider> -->
          <el-row class="Selected_tableH">
              <span style="line-height: 40px;">已选择：</span>
              <el-col class="Selected">
                  <el-tag v-for="(tag,index) in selectedListD"
                      :key="tag.id"
                      closable  @close="handleClose(tag.id)">
                      <!-- {{tag.parameterNote}} -->
                      {{tag.parameterNote}}
                  </el-tag>
              </el-col>
          </el-row>
          <el-row>
              <el-col :span="24">可选择字段</el-col>
          </el-row>
          <div style="height: 600px;overflow: auto;">
              <div class="SelectBox" v-for="(tableH,ind) in TableOptionsAlls">
              <el-row>
                  <el-col :span="24" class="work_box"><el-checkbox :indeterminate="isIndeterminatein[tableH.id]" v-model="checkAll[tableH.id]"  @click.native="handleCheckAllChange($event, tableH.id)" style="width:100px">全选</el-checkbox>{{tableH.parameterNote}}</el-col>
              </el-row>
              <el-row style="padding: 0 10px;">
                  <el-checkbox-group 
                      v-model="selectedList" @change="handleCheckedCitiesChange">
                      <el-checkbox v-for="child in tableH.movieList" :label="child.id" :key="child.
id">{{child.parameterNote}}</el-checkbox>
                  </el-checkbox-group>
              </el-row>
          </div>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button size="mini" @click="showSetTable = false">取 消</el-button>
              <el-button type="primary" plain size="mini" @click="handleSetTable">确定
              </el-button>

          </span>
      </el-dialog>

  </div>
</template>
<script>
// 测试数据
import {
  listEmployee,
  getEmployee,
  delEmployee,
  addEmployee,
  updateEmployee,
  adjustEmployee,
  setEmployeeExcel,
  addEmployeeGrading,
  areaSmall,
  getAreaList,
} from "@/api/hr/employee";
import { listMechanism } from "@/api/hr/department";
import { listJob } from "@/api/hr/job";
import { listDictByType } from "@/api/hr/dictConfig";
import { organizationTypeConfig } from "@/config/staticDict";
import { fileUploadUrl, imgUpload } from "@/api/hr/upload";
import archives from "@/views/hr/employee/archives.vue";
import { eduTypeConfig, disabilityTypeConfig } from "@/config/staticDict";
import { validateMobile, validateIdCard } from "@/utils/hoValidate.js";
import { upPassword } from "@/api/hr/member"; //修改密码
import { removeToken } from "@/utils/auth"; //移除
import { GetAllTableH,GetRequireAllTableH } from "@/api/hr/employee" //表头设置
//证书组件
import EmployeeFiles from "@/views/hr/employee/cert-file";
import Page from "@/views/components/page";
//合同组件
// import Agreement from "@/views/hr/agreement";
import { copyHasProperty } from "@/utils/tools";
import { Message, Notification } from "element-ui";
import { getToken, getUid } from "@/utils/auth";
// import { setAbilityExcel } from "@/api/hr/ability";
import { selectList } from "@/api/hr/rank";
import { showDataList } from "@/api/hr/report";
import { rankList } from "@/api/hr/rank"; //职级表
import { getRanks } from "@/api/hr/gradePost";
import axios from 'axios';
import { DebuggerUtil } from "@antv/s2";

export default {
  components: {
      EmployeeFiles,
      Page,
  },
  computed: {
      archives() {
          return archives;
      },
  },

  data() {
      // 检查俩次密码是否一致
      var validatePass2 = (rule, value, callback) => {
          if (value === "") {
              callback(new Error("请再次输入密码"));
          } else if (value !== this.formPassword.newPassword) {
              callback(new Error("俩次输入的密码不一致"));
          } else {
              callback();
          }
      };

      return {
          // 按钮loading
          buttonLoading: false,
          passwordAndText: "password",
          LookIco: "noLook",
          passwordAndTextTo: "password",
          LookIcoTo: "noLook",
          props: {
              lazy: true,
              lazyLoad(node, resolve) {
                  const { level } = node;
                  if (level == 0) {
                      getAreaList({ extName: "" }).then((res) => {
                          let dataArr = res.data.list;
                          let nodes = [];
                          dataArr = JSON.stringify(dataArr);
                          dataArr = dataArr.replace(/text/g, "label");
                          dataArr = JSON.parse(dataArr);

                          dataArr.forEach((item, index) => {
                              if (item.level == 0) {
                                  nodes.push(item);
                              }
                          });
                          setTimeout(() => {
                              // 只有这种格式数据才会回显到input框中
                              nodes = nodes.map((item) => ({
                                  value: item.extName,
                                  label: item.extName,
                                  id: item.id,
                                  leaf: level >= 2,
                              }));
                              // 通过调用resolve将子节点数据返回，通知组件数据加载完成
                              resolve(nodes);
                          }, 10);
                      });
                  } else {
                      areaSmall({ id: node.data.id, extName: "" }).then((res) => {
                          // if (res.data[0].level === 1) {
                          //   areaSmall({ id: res.data[0].id }).then((res) => {
                          //     if (res) {
                          //       let dataArr = res.data;
                          //       dataArr = JSON.stringify(dataArr);
                          //       dataArr = dataArr.replace(/name/g, "label");
                          //       dataArr = JSON.parse(dataArr);
                          //       setTimeout(() => {
                          //         dataArr = dataArr.map((item) => ({
                          //           value: item.extName,
                          //           label: item.extName,
                          //           id: item.id,
                          //           leaf: level >= 2,
                          //         }));
                          //         // 通过调用resolve将子节点数据返回，通知组件数据加载完成
                          //         resolve(dataArr);
                          //       }, 1000);
                          //     }
                          //   });
                          // } else {
                          // areaSmall({ id: res.data[0].id }).then((res) => {
                          if (res) {
                              let dataArr = res.data;
                              dataArr = JSON.stringify(dataArr);
                              dataArr = dataArr.replace(/name/g, "label");
                              dataArr = JSON.parse(dataArr);
                              setTimeout(() => {
                                  dataArr = dataArr.map((item) => ({
                                      value: item.extName,
                                      label: item.extName,
                                      id: item.id,
                                      leaf: level >= 2,
                                  }));
                                  // 通过调用resolve将子节点数据返回，通知组件数据加载完成
                                  resolve(dataArr);
                              }, 10);
                          }
                          // });
                          // }
                      });
                  }
              },
          },

          // 遮罩层
          loading: true,
          // 选中数组
          ids: [],
          // 非单个禁用
          single: true,
          // 非多个禁用
          multiple: true,
          // 显示搜索条件
          showSearch: true,
          moreSearch: false,
          moreSearchText: "显示更多查询",
          // 总条数
          total: 0,
          //职级
          theRankList: [],
          //认定职级
          rankListRD: [],

          //认定职务
          dutiesListRD: [],
          //人员身份
          identityList: [],
          //从事专业
          engagingList: [],
          //从事专业类别
          majorTypeList: [],
          //入职方式
          entryMethodList: [],
          //学习形式
          studyMethodList: [],
          //绩效分类
          JXList: [],
          // 员工表格数据
          employeeList: [],
          // 弹出层标题
          title: "",
          // 是否显示弹出层
          open: false,
          // 查询参数
          queryParams: {
              pageNum: 1,
              pageSize: 10,
              employeeName: undefined,
              graduationTime: undefined,
              employeeBirthday: undefined,
              employeeSex: undefined,
              employeeRole: undefined,
              accountNumber: undefined,
              accountPassword: undefined,
              phone: undefined,
              peopleType: undefined,
              token: undefined,
              school: undefined,
              formalSchooling: undefined,
              major: undefined,
              employmentDate: undefined,
              employeeRank: undefined,
              leaveTime: undefined,
              entryTime: undefined,
              postId: undefined,
              departmentId: undefined,
              institutionId: undefined,
              email: undefined,
              idCard: undefined,
              state: "", //"1,2",//不查离职员工 , 0 离退员工
              minEmploymentTime: undefined, //最小从业时间 (在职/从业时间)
              maxEmploymentTime: undefined, //最大从业时间 (在职/从业时间)
              minEntryTime: undefined, //最小入职时间 (本院在岗时间)
              maxEntryTime: undefined, //最大入职时间 (在院岗时间)
              reasonLeaving: undefined, //离职原因
              peopleState: undefined, //人员状态
              identityValue: undefined, //人员身份
              employLevel: undefined, //岗位级别
              learningForms: undefined, //学习形式
          },
          // 表单参数
          form: {},
          // 表单校验
          rules: {
              //   id: [
              //     { required: true, message: 'id不能为空', trigger: 'blur' }
              //   ],
              employeeName: [
                  { required: true, message: "员工姓名不能为空", trigger: "blur" },
              ],
              graduationTime: [
                  { required: true, message: "毕业时间不能为空", trigger: "blur" },
              ],
              employeeBirthday: [
                  { required: true, message: "员工出生年月不能为空", trigger: "blur" },
              ],
              employeeSex: [
                  { required: true, message: "性别不能为空", trigger: "change" },
              ],
              employeeRole: [
                  { required: true, message: "角色不能为空", trigger: "blur" },
              ],
              engagingProfession: [
                  { required: true, message: "从事专业不能为空", trigger: "blur" },
              ],
              majorType: [
                  { required: true, message: "从事专业不能为空", trigger: "blur" },
              ],
              accountNumber: [
                  { required: true, message: "账号不能为空", trigger: "blur" },
              ],
              accountPassword: [
                  { required: true, message: "密码不能为空", trigger: "blur" },
              ],
              phone: [
                  { required: true, message: "手机号不能为空", trigger: "blur" },
                  {
                      validator: validateMobile,
                      trigger: "blur",
                  },
              ],
              // phone1: [
              //   { required: true, message: "手机号不能为空", trigger: "blur" },
              //   {
              //     validator: validateMobile,
              //     trigger: "blur",
              //   },
              // ],
              identityValue: [
                  { required: true, message: "人员身份不能为空", trigger: "change" },
              ],
              school: [
                  { required: true, message: "毕业学校不能为空", trigger: "blur" },
              ],
              formalSchooling: [
                  { required: true, message: "学历不能为空", trigger: "blur" },
              ],
              major: [{ required: true, message: "专业不能为空", trigger: "blur" }],
              employmentDate: [
                  { required: true, message: "从业时间不能为空", trigger: "blur" },
              ],
              // rank: [
              //   {required: true, message: "级别不能为空", trigger: "blur"}
              // ],
              joinOrganizationTime: [
                  {
                      required: true,
                      message: "加入组织时间不能为空",
                      trigger: "change",
                  },
              ],
              entryTime: [
                  { required: true, message: "入职时间不能为空", trigger: "blur" },
              ],
              postId: [
                  { required: true, message: "所属科室不能为空", trigger: "blur" },
              ],
              departmentId: [
                  { required: true, message: "所属部门不能为空", trigger: "blur" },
              ],
              institutionId: [
                  { required: true, message: "所属机构不能为空", trigger: "blur" },
              ],
              type: [
                  { required: true, message: "人员类型不能为空", trigger: "blur" },
              ],
              email: [
                  { required: true, message: "邮箱不能为空", trigger: "blur" },
                  {
                      type: "email",
                      message: "请输入正确的邮箱地址",
                      trigger: ["blur"],
                  },
              ],
              idCard: [
                  { required: true, message: "身份证不能为空", trigger: "blur" },
                  // {
                  //   validator: validateIdCard,
                  //   trigger: "blur",
                  // },
                  { validator: this.validateIdNumber, trigger: "blur" },
              ],
              peopleState: [
                  { required: true, message: "人员状态不能为空", trigger: "blur" },
              ],
              performanceType: [
                  { required: true, message: "绩效分类不能为空", trigger: "blur" },
              ],

              nation: [
                  { required: true, message: "民族不能为空", trigger: "change" },
              ],
              hometown: [
                  { required: true, message: "籍贯不能为空", trigger: "blur" },
              ],
              employmentTime: [
                  { required: true, message: "工作时间不能为空", trigger: "change" },
              ],
              academicDegree: [
                  { required: true, message: "学位不能为空", trigger: "blur" },
              ],
              politicalOutlook: [
                  {
                      required: true,
                      message: "政治面貌不能为空",
                      trigger: "change",
                  },
              ],

              learningForms: [
                  { required: true, message: "学习方式不能为空", trigger: "change" },
              ],
              entryMethod: [
                  { required: true, message: "入职方式不能为空", trigger: "change" },
              ],

              toHospitalTime: [
                  { required: true, message: "来院时间不能为空", trigger: "change" },
              ],
          },
          openPassword: false,
          formPassword: {},
          rulesPassword: {
              newPasswordTo: [
                  { required: true, validator: validatePass2, trigger: "blur" },
              ],
              newPassword: [
                  { required: true, message: "新密码不能为空", trigger: "blur" },
              ],
          },
          //下拉菜单选项(字典)
          deparmentList: [],
          bumenList: [],
          keshiList: [],
          jobList: [],
          eduList: [],
          genderList: [],

          //搜索部门下拉
          bumenQueryList: [],
          keshiQueryList: [],

          adjustOpen: false,
          adjustDict: [],
          adjustForm: {
              id: undefined,
              accountNumber: undefined,
              employeeRole: undefined,
              postId: undefined,
              departmentId: undefined,
              institutionId: undefined,
              upType: undefined,
          },
          adjustRules: {
              id: [{ required: true, message: "id不能为空", trigger: "blur" }],
              accountNumber: [
                  { required: true, message: "用户账号不能为空", trigger: "blur" },
              ],
              employeeRole: [
                  { required: true, message: "角色不能为空", trigger: "blur" },
              ],
              postId: [{ required: true, message: "科室不能为空", trigger: "blur" }],
              departmentId: [
                  { required: true, message: "部门不能为空", trigger: "blur" },
              ],
              institutionId: [
                  { required: true, message: "机构不能为空", trigger: "blur" },
              ],
              upType: [
                  { required: true, message: "调整类型不能为空", trigger: "blur" },
              ],
          },
          avatarImg: "",
          fileUploadUrl,
          fileList: [],
          archiveComponentName: "",
          employeeId: "",
          archiveOpen: false,
          archiveTitle: "",
          agreementOpen: false,
          politicalDict: [], //政治面貌字典,
          nationDict: [], //民族字典
          employeeTypeDict: [], //人员类型字典
          eduTypeConfig, //学制类型字典
          organizationTypeConfig, //编制字典
          disabilityTypeConfig, //残疾状态字典
          stateDict: [], //员工状态字典
          headers: {
              //上传文件头
              token: getToken(),
          },
          state: undefined,
          sendMsgOpen: false,
          sendMsgForm: {
              count: [],
          },

          selectRows: [], //选中行的数据
          rankList: [],

          msgRules: {
              employeeId: [
                  { required: true, message: "employeeId不能为空", trigger: "blur" },
              ],
              grading: [
                  { required: true, message: "初步定级不能为空", trigger: "change" },
              ],
              dutyTime: [
                  { required: true, message: "初步到岗时间不能为空", trigger: "blur" },
              ],
          },

          employmentTimeRange: [],
          entryTimeRange: [],
          reasonLeavingDict: [],
          buttons: [],
          // 信息完善度
          InformationList: [
              {
                  value: '0',
                  label: '0%~20%'
              },
              {
                  value: '1',
                  label: '20%~40%'
              },
              {
                  value: '2',
                  label: '40%~60%'
              },
              {
                  value: '3',
                  label: '60%~80%'
              },
              {
                  value: '4',
                  label: '80%~100%'
              },
          ],
          // daochu
          dialogVisible: false,
          pageType: [],
          isExport: true,
          // 导出按钮限制
          showExport: true,
          exportOptions: [
              {
                  id: 99,
                  label: "全部",
                  name: "全部",
                  componentnext: "全部"
              },
              {
                  id: 0,
                  label: "基本信息",
                  name: "基本信息",
                  componentnext: "Information"
              },
              {
                  id: 1,
                  label: "合同及协议",
                  name: "合同及协议",
                  componentnext: "Contract"
              },
              {
                  id: 2,
                  label: "任职信息",
                  name: "任职信息",
                  componentnext: "Appoint"
              },
              {
                  id: 3,
                  label: "人事档案",
                  name: "人事档案",
                  componentnext: "Archives"
              },
              {
                  id: 4,
                  label: "奖惩记录",
                  name: "奖惩记录",
                  componentnext: "RewardsAndPunishments"
              },
              {
                  id: 5,
                  label: "职称信息",
                  name: "职称信息",
                  componentnext: "Title"
              },
              {
                  id: 6,
                  label: "社会兼职",
                  name: "社会兼职",
                  componentnext: "PartTimeJob"
              },
              {
                  id: 7,
                  label: "政治面貌",
                  name: "政治面貌",
                  componentnext: "Politics"
              },
              {
                  id: 8,
                  label: "培训情况",
                  name: "培训情况",
                  componentnext: "Train"
              },
              {
                  id: 9,
                  label: "继续教育",
                  name: "继续教育",
                  componentnext: "Education2"
              },
              {
                  id: 10,
                  label: "工作经历",
                  name: "工作经历",
                  componentnext: "WorkExperience"
              },
              {
                  id: 11,
                  label: "履职考核",
                  name: "履职考核",
                  componentnext: "Examine"
              },
              {
                  id: 12,
                  label: "教育经历",
                  name: "教育经历",
                  componentnext: "Education"
              },
              {
                  id: 13,
                  label: "科研",
                  name: "科研",
                  componentnext: "ScientificResearch"
              },
              {
                  id: 14,
                  label: "执业信息",
                  name: "执业信息",
                  componentnext: "Practice"
              },
              {
                  id: 15,
                  label: "外部交流",
                  name: "外部交流",
                  componentnext: "ExternalCommunication"
              },
              {
                  id: 16,
                  label: "变动记录",
                  name: "变动记录",
                  componentnext: "Change"
              },
              {
                  id: 17,
                  label: "家庭关系",
                  name: "家庭关系",
                  componentnext: "Family"
              },
              {
                  id: 18,
                  label: "进修",
                  name: "进修",
                  componentnext: "ContinuingEducation"
              },
              {
                  id: 19,
                  label: "规培",
                  name: "规培",
                  componentnext: "RegulatedTraining"
              }
          ],
          statistics: {
              allNumber: 0,
              contractNum: 0,
              dispatchNum: 0,
              organizationNum: 0,
              retireNum: 0,
              retirementNum: 0
          },
          gangweiList: [],
          // 新增
          showSetTable:false,
          TableHeaders:[],
          queryD:{},
          selectedList: [], //已选字段
          selectedListD:[],//处理字段用于显示渲染
          checkedList:[],  //存放不同表的字段
          oldselectedList:[],  //已选旧数据
          TableOptionsAlls:[],  //所有表头字段数据
          ids:[], //获取所有子级字段id
          fatherIds:[],  //获取所有fatherId
          dateziduanS:[],  //获取所有时间字段
          isIndeterminatein:[],  //全选框状态 true:显示为半选样式，false：不显示
          checkAll:[], //检查是否全选  true: 显示为全选样式，false：不显示
      };
  },
  created() {
      this.getDepartList(); //获取组织机构配置
      this.getJobList(); //获取岗位配置
      this.getDictData();
      this.buttons = this.$route.meta.buttons;
      this.getRankList();
      // 岗位等级
      this.getGangwei();
      // 获取全部表头
      this.SetTableHeader();
      // 根据条件获取表头
      this.GetRequireAllTableHeader(this.queryD);
  },
  mounted() {
      if (this.$route.params.sql) {
          //如果是报表跳转的
          showDataList(this.$route.params.sql).then((res) => {
              // this.total = 2
              this.employeeList = res.data.data;
              // console.log(this.employeeList);
              this.loading = false;
          });
      } else {
          this.getList();
      }
      
  },
  methods: {
      // 岗位等级
      getGangwei() {
          getRanks({ type: 66 }).then(res => {
              // console.log(res)
              this.gangweiList = res.data;
          })
      },
      handlePassword(row) {
          this.openPassword = true;
          this.resetForm("formPassword");
          this.formPassword.id = row.id;
      },

      validateIdNumber(rule, value, callback) {
          // 身份证号校验逻辑
          const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
          if (reg.test(value)) {
              this.extractInfoFromIdNumber(value);
              callback();
          } else {
              callback(new Error("身份证号格式不正确"));
              this.form.employeeBirthday = "";
              this.form.employeeSex = "";
          }
      },
      extractInfoFromIdNumber(idNumber) {
          // 提取出生年月和性别
          let year, month, day, gender;
          if (idNumber.length === 15) {
              year = idNumber.substring(6, 8);
              month = idNumber.substring(8, 10);
              day = idNumber.substring(10, 12);
              gender = idNumber.substring(14, 15) % 2 === 0 ? 20 : 19;
              this.formData.birthDate = `19${year}-${month}-${day}`;
              this.formData.gender = gender;
          } else if (idNumber.length === 18) {
              year = idNumber.substring(6, 10);
              month = idNumber.substring(10, 12);
              day = idNumber.substring(12, 14);
              gender = idNumber.substring(16, 17) % 2 === 0 ? 20 : 19;
              this.form.employeeBirthday = `${year}-${month}-${day}`;
              this.form.employeeSex = gender;
          }
      },
      CanNo() {
          console.log(this.LookIco);
          if (this.LookIco === "canLook") {
              this.LookIco = "noLook";
              this.passwordAndText = "password";
          } else {
              this.LookIco = "canLook";
              this.passwordAndText = "text";
          }
      },
      CanNoTo() {
          if (this.LookIcoTo === "canLook") {
              this.LookIcoTo = "noLook";
              this.passwordAndTextTo = "password";
          } else {
              this.LookIcoTo = "canLook";
              this.passwordAndTextTo = "text";
          }
      },

      validatePass2(rule, value, callback) {
          //校验两次密码是否一致
          if (value === "") {
              callback(new Error("请再次输入密码"));
          } else if (value !== this.form.password) {
              callback(new Error("俩次输入的密码不一致"));
          } else {
              callback();
          }
      },

      submitFormPassword() {
          this.$refs["formPassword"].validate((valid) => {
              if (valid) {
                  this.formPassword.newPasswordTo = undefined;
                  upPassword(this.formPassword)
                      .then((res) => {
                          this.$modal.msgSuccess("修改成功");
                          this.openPassword = false;
                          // setTimeout(() => {
                          //   removeToken();
                          //   this.$router.go(0);
                          // }, 2000);
                      })
                      .finally(() => {
                          this.openPassword = false;
                      });
              }
          });
      },
      changeMoreSearch() {
          if (this.moreSearch) {
              this.moreSearchText = "显示更多查询";
              this.moreSearch = !this.moreSearch;
          } else {
              this.moreSearchText = "隐藏";
              this.moreSearch = !this.moreSearch;
          }
      },

      handleSizeChange(val) {
          // console.log(`每页 ${val} 条`);
          this.queryParams.pageSize = val;
          this.getList();
      },

      handleCurrentChange(val) {
          // console.log(`当前页: ${val}`);
          this.queryParams.pageNum = val;
          this.getList();
      },

      employmentTimeChange(e) {
          console.log("employmentTimeChange", e);
          this.queryParams.minEmploymentTime = e[0];
          this.queryParams.maxEmploymentTime = e[1];
      },

      entryTimeChange(e) {
          console.log("entryTimeChange", e);
          this.queryParams.minEntryTime = e[0];
          this.queryParams.maxEntryTime = e[1];
      },

      clearTimeRangeParams() {
          this.employmentTimeRange = [];
          this.entryTimeRange = [];
          this.queryParams.minEmploymentTime = undefined;
          this.queryParams.maxEmploymentTime = undefined;
          this.queryParams.minEntryTime = undefined;
          this.queryParams.maxEntryTime = undefined;
      },

      //待入职员工发送信息
      handleSendMsg() {
          if (!this.ids || this.ids?.length < 1) {
              Message({ message: "请选择记录", type: "error" });
              return;
          }
          let rows = JSON.parse(JSON.stringify(this.selectRows));
          let sendMsgList = [];
          let flag = true;
          rows.forEach((item, index) => {
              console.log(item.state);
              if (item.state != 2) {
                  flag = false;
                  return;
              }
              let row = {};
              row.employeeId = item.id;
              row.stateValue = item.stateValue;
              row.employeeName = item.employeeName;
              row.grading = undefined;
              row.dutyTime = undefined;
              sendMsgList.push(row);
          });
          if (flag == false) {
              Message({ message: "仅可以选择等待入职的员工", type: "error" });
              return;
          }
          this.sendMsgForm.count = sendMsgList;
          this.sendMsgOpen = true;
      },

      //提交发送的信息
      submitSendMsg() {
          this.$refs.msgForm.validate((valid) => {
              if (valid) {
                  this.sendMsgForm.createBy = getUid();
                  this.buttonLoading = true;
                  addEmployeeGrading(this.sendMsgForm)
                      .then((res) => {
                          Message({ message: "提交成功", type: "success" });
                          this.sendMsgOpen = false;
                          this.getList();
                      })
                      .finally(() => {
                          this.buttonLoading = false;
                      });
              } else {
                  Message({ message: "请填写信息", type: "error" });
              }
          });
      },

      getRowKey(row) {
          return row.id;
      },

      //获取职级(人员定级)
      getRankList() {
          selectList({}).then((res) => {
              this.rankList = res.data;
          });
      },

      onStateChange(data) {
          this.queryParams.state = data;
      },

      //文件上传(导入成功后的回调)
      onUpSuccess(response, file, fileList) {
          if (response.code == 1) {
              Message({ message: "上传成功，正在解析" });
              let rel_url = response.data[0].relative_url;
              //上传成功后,向导入数据的接口发送一个服务器文件地址
              setEmployeeExcel(rel_url)
                  .then((res) => {
                      //解析excel成功,重新获取列表
                      this.getList();
                  })
                  .finally(() => {
                      this.fileList = [];
                  });
          } else {
              Notification.error({ title: response.msg });
          }
      },

      handleDetail(row) {
          const id = row.id;
          if (!id) {
              Notification.error({ title: "type有误" });
              return;
          }
          this.$router.push({ path: "/employee/home", query: { id, type: "look" } });
      },

      //头像上传
      handleAvatarSuccess(res, file) {
          if (res.code == 1) {
              this.form.img = res.data[0]?.relative_url;
              this.avatarImg = res.data[0].url;
          }
      },

      cancelArchive() {
          this.archiveTitle = "";
          this.archiveComponentName = "";
          this.archiveOpen = false;
      },

      /** 查询员工列表 */
      getList() {
          this.loading = true;
          listEmployee(this.queryParams).then((response) => {
              this.employeeList = response.data.list;

              if (response.data.peopleNum) {
                  // 统计人数
                  this.statistics = response.data.peopleNum;
              }
              this.total = response.data.total;
              this.loading = false;
          });
      },
      homeChange(e) {
          console.log(e);
      },

      getDictData() {
          //获取学历字典
          listDictByType(1).then((res) => {
              this.eduList = res.data;
          });
          //获取性别字典
          listDictByType(3).then((res) => {
              this.genderList = res.data;
          });
          //获取政治面貌字典
          listDictByType(10).then((res) => {
              this.politicalDict = res.data;
          });
          //获取民族面貌字典
          listDictByType(28).then((res) => {
              this.nationDict = res.data;
          });
          //获取面貌字典
          listDictByType(25).then((res) => {
              this.employeeTypeDict = res.data;
          });

          //获取岗位调整类型字典
          listDictByType(15).then((res) => {
              this.adjustDict = res.data;
          });

          //获取员工状态字典
          listDictByType(26).then((res) => {
              this.stateDict = res.data;
          });

          //获取认定职务字典
          listDictByType(32).then((res) => {
              this.dutiesListRD = res.data;
          });
          //获取认定职级字典
          listDictByType(31).then((res) => {
              this.rankListRD = res.data;
          });
          //获取人员身份字典
          listDictByType(27).then((res) => {
              this.identityList = res.data;
          });
          //职级
          rankList({}).then((res) => {
              this.theRankList = res.data.list;
          });
          //入职方式
          listDictByType(37).then((res) => {
              this.entryMethodList = res.data;
          });
          //学习方式
          listDictByType(38).then((res) => {
              this.studyMethodList = res.data;
          });
          //学习方式
          listDictByType(40).then((res) => {
              this.JXList = res.data;
          });
          //从事专业
          listDictByType(40).then((res) => {
              this.engagingList = res.data;
          });
          listDictByType(30).then((res) => {
              this.majorTypeList = res.data;
          });
      },

      //获取岗位列表配置
      getJobList() {
          listJob({}).then((res) => {
              this.jobList = res.data.list;
          });
      },

      departmentChange(e) {
          this.resetDepart(1);
          let curr = this.deparmentList.filter((item) => {
              return item.id == e;
          });
          this.bumenList = curr[0]?.dson;
      },

      bumenChange(e) {
          this.resetDepart(2);
          if (this.bumenList.length !== 0) {
              //防止bumenList为空时报错
              let curr = this.bumenList.filter((item) => {
                  return item.id == e;
              });
              this.keshiList = curr[0]?.dson;
          }
      },

      resetDepart(changeLev) {
          if (changeLev == 1) {
              this.bumenList = [];
              this.keshiList = [];
              this.form.departmentId = undefined;
              this.form.postId = undefined;

              this.adjustForm.departmentId = undefined;
              this.adjustForm.postId = undefined;
          }
          if (changeLev == 2) {
              this.keshiList = [];
              this.form.postId = undefined;
              this.adjustForm.postId = undefined;
          }
      },

      //搜索框部门选择
      deptChangeQuery(e) {
          this.resetDepartQuery(1);
          let curr = this.deparmentList.filter((item) => {
              return item.id == e;
          });
          this.bumenQueryList = curr[0]?.dson;
      },

      bumenChangeQuery(e) {
          this.resetDepartQuery(2);
          let curr = this.bumenQueryList.filter((item) => {
              return item.id == e;
          });
          this.keshiQueryList = curr[0]?.dson;
      },

      resetDepartQuery(changeLev) {
          if (changeLev == 1) {
              this.bumenQueryList = [];
              this.keshiQueryList = [];
              this.queryParams.departmentId = undefined;
              this.queryParams.postId = undefined;
          }
          if (changeLev == 2) {
              this.keshiQueryList = [];
              this.queryParams.postId = undefined;
          }
      },

      getDepartList() {
          listMechanism({ state: 1 }).then((res) => {
              this.deparmentList = res.data;
          });
      },

      // 取消按钮
      cancel() {
          this.open = false;
          this.reset();
          this.resetDepart();
      },

      // 表单重置
      reset() {
          this.form = {
              id: undefined,
              employeeName: undefined,
              graduationTime: undefined,
              employeeBirthday: undefined,
              employeeSex: undefined,
              employeeRole: undefined,
              accountNumber: undefined,
              accountPassword: undefined,
              phone: undefined,
              identityValue: undefined,
              //token: undefined,
              school: undefined,
              formalSchooling: undefined,
              major: undefined,
              employmentDate: undefined,
              rank: undefined,
              leaveTime: undefined,
              entryTime: undefined,
              postId: undefined,
              departmentId: undefined,
              institutionId: undefined,
              type: undefined,
              email: undefined,
              idCard: undefined,
              state: undefined,
              // createBy: undefined,
              // createTime: undefined,
              // updateBy: undefined,
              // updateTime: undefined,
              organization: undefined, //编制
              peopleRank: undefined, //职级
              politicalOutlook: undefined, //政治面貌
              nation: undefined, //民族
              physicalDisability: undefined, //是否残疾
              //img: undefined,
              concernCultivate: undefined,
          };
          this.resetForm("form");
      },

      /** 搜索按钮操作 */
      handleQuery() {
          this.queryParams.pageNum = 1;
          this.getList();
      },

      /** 重置按钮操作 */
      resetQuery() {
          this.resetForm("queryForm");
          this.clearTimeRangeParams();
          this.handleQuery();
      },

      // 多选框选中数据
      handleSelectionChange(selection) {
          this.ids = selection.map((item) => item.id);
          this.selectRows = selection;
          this.single = selection.length !== 1;
          this.multiple = !selection.length;
      },

      /** 新增按钮操作 */
      handleAdd() {
          this.reset();
          this.open = true;
          this.title = "添加员工";
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
          //this.loading = true
          this.reset();
          // const id = row.id || this.ids[0];
          // if (!row.id) {
          //   let rows = this.employeeList.filter((item, index) => {
          //     return id == item.id;
          //   });
          //   row = rows[0];
          // }
          // console.log("row", row);
          // this.form = copyHasProperty(this.form, row);
          this.form = { ...row };
          this.open = true;
          this.title = "修改员工";
          this.avatarImg = row.img; //初始化头像显示
          this.form.img = row.img?.substring(row.img?.indexOf("/upload")); //截取掉host取相当地址,以免修改时提交绝对地址
          //this.departmentChange(this.form.institutionId)
          //this.bumenChange(this.form.departmentId)

          // getEmployee(id).then(response => {
          //   this.loading = false;
          //   this.form = copyHasProperty(this.form,response.data);
          //   this.open = true;
          //   this.title = '修改员工';
          //   //初始化修改时默认数据
          //   this.departmentChange(this.form.institutionId)
          //   this.bumenChange(this.form.departmentId)
          // })
      },

      /**调岗按钮操作**/
      handleAdjust(row) {
          console.log(row.institutionId, row.departmentId, row.postId);
          this.departmentChange(row.institutionId);
          this.bumenChange(row.departmentId); // 11.07决绝无法点击调岗按钮时//注释
          this.adjustForm = copyHasProperty(this.adjustForm, row);
          this.adjustForm.postId = row.postId * 1; //数据回显bug
          this.adjustOpen = true;
      },

      // 取消按钮
      cancelAdjust() {
          this.adjustOpen = false;
          this.resetForm("adjustForm");
      },

      //提交调岗信息
      submitAdjustForm() {
          this.$refs["adjustForm"].validate((valid) => {
              if (valid) {
                  //console.log(this.adjustForm);return;
                  this.buttonLoading = true;
                  adjustEmployee(this.adjustForm)
                      .then((res) => {
                          this.$modal.msgSuccess("修改成功");
                          this.adjustOpen = false;
                          this.getList();
                      })
                      .finally(() => {
                          this.buttonLoading = false;
                      });
              }
          });
      },

      /** 提交按钮 */
      submitForm() {
          this.$refs["form"].validate((valid) => {
              if (valid) {
                  this.buttonLoading = true;
                  if (this.form.id != null) {
                      this.form.upType = 1;
                      updateEmployee(this.form)
                          .then((response) => {
                              this.$modal.msgSuccess("修改成功");
                              this.open = false;
                              this.getList();
                          })
                          .finally(() => {
                              this.buttonLoading = false;
                          });
                  } else {
                      this.form.hometown = this.form.hometown.toString();
                      addEmployee(this.form)
                          .then((response) => {
                              this.$modal.msgSuccess("新增成功");
                              this.open = false;
                              this.getList();
                          })
                          .finally(() => {
                              this.buttonLoading = false;
                          });
                  }
              }
          });
      },

      /** 删除按钮操作 */
      handleDelete(row) {
          const ids = row.id || this.ids;
          this.$modal
              .confirm('是否确认删除员工编号为"' + ids + '"的数据项？')
              .then(() => {
                  this.loading = true;
                  return delEmployee(ids);
              })
              .then(() => {
                  this.loading = false;
                  this.getList();
                  this.$modal.msgSuccess("删除成功");
              })
              .catch(() => { })
              .finally(() => {
                  this.loading = false;
              });
      },

      /** 导出按钮操作*/
      handleExport() {
          if (this.pageType.length <= 0) {
              this.$message.error('请选择导出模块');
          } else {
              if (this.pageType == 99) {
                  this.pageType = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
              }
              axios({
                  method: "get",
                  url: process.env.VUE_APP_BASE_API + "/v1/employeeAppointment/getExcel?pageType=" + this.pageType.toString(),
                  responseType: "blob"
              }).then(res => {
                  console.log("excel", res);

                  if (res.status == 200) {
                      let fileName = `人员导出文件_${new Date().getTime()}.xls`;
                      const elink = document.createElement('a')
                      elink.download = fileName;
                      elink.style.display = 'none'
                      elink.href = URL.createObjectURL(res.data)
                      document.body.appendChild(elink)
                      elink.click()
                      URL.revokeObjectURL(elink.href)
                      document.body.removeChild(elink)

                  } else {
                      this.$message.error(res.message || '下载失败！')
                  }

                  this.dialogVisible = false;
                  this.showExport = true;
                  this.pageType = [];
              })
          }
      },

      //下载模板
      handleDownDeptTemplate() {
          this.download(
              "/sc/manage/downExcel",
              {
                  //...this.queryParams
              },
              `员工模板_${new Date().getTime()}.xls`
          );
      },
       //移除已选项
      handleClose(tag) {
          console.log(tag)
          var tt=[]
          this.selectedList.splice(this.selectedList.indexOf(tag), 1);
          this.selectedListD.forEach((item,ind)=>{
             if(item.id==tag){
              this.selectedListD.splice(ind,1)
             }
          })
          
      },
      // 获取全部表头数据
      SetTableHeader(){
          this.TableHeaders=[]
          GetAllTableH({}).then((response) => {
              if(response.data){
                  this.TableOptionsAlls=response.data.list
              }
              this.isIndeterminatein=this.TableOptionsAlls.reduce((obj,item)=>{
                  obj[item.id]=false
                   return obj
              },{})  
              this.checkAll=this.TableOptionsAlls.reduce((obj,item)=>{
                  obj[item.id]=false
                   return obj
              },{}) 

            console.log(this.checkAll)
            console.log(this.isIndeterminatein)
          }); 
          this.selectedList=[].concat(this.oldselectedList)
         
      },
      // 选择选项
      handleCheckedCitiesChange(value) {
          debugger
          console.log(value)
          this.selectedListD=[]
          var AllHeaders=[]
          this.TableOptionsAlls.forEach((item,ind)=>{
              item.movieList.forEach((item1,ind1)=>{
                  AllHeaders.push(item1)
                  value.forEach((item2,ind2)=>{
                      if(value[ind2]==item1.id){
                          this.selectedListD.push(item1)
                      }
                  })
              })
          })
          
      },
      // 全选
      handleCheckAllChange(item, id) {
          debugger
          // this.checkedCities = val ? cityOptions : [];
          this.isIndeterminate[id] = false;
      },
      //取消设置
      CancleBtn(){
          this.showSetTable=false
      },
      // 表头设置数据提交
      handleSetTable(){
          this.loading = true;
          var FatherIds=[]
          var newArr=[]
          this.ids=""
          this.fatherIds=""
          if(this.selectedListD!=''){
           this.selectedListD.forEach((item,index)=>{
              this.ids += `${this.ids.length ? "," : ""}${item.id}`;
              FatherIds.push(item.fatherId)
            })
            
            for (let i = 1; i < FatherIds.length; i++) {
              
                  if (newArr.indexOf(FatherIds[i])===-1) {
                      newArr.push(FatherIds[i])
                  }
              }
              newArr.forEach(item=>{
                  this.fatherIds +=`${this.fatherIds.length ? "," : ""}${item}`;
              })
          }
          // 根据条件获取表头字段
          this.queryD={
              "ids": this.ids, 
              "fatherIds": this.fatherIds 
              }
          this.GetRequireAllTableHeader(this.queryD)
          this.oldselectedList=[].concat(this.selectedList)
          this.showSetTable=false
          
      },
      // 根据条件获取表头字段
      GetRequireAllTableHeader(query){
          this.TableHeaders=[]
          GetRequireAllTableH(query).then((response) => {
                 if(response.data){
                  this.selectedListD=response.data.list
                  response.data.list.forEach((item1,index)=>{
                      // debugger
                      this.selectedList.push(item1.id)
                      if(item1.parameterName!="number"&&item1.parameterName!="employeeName"){
                          this.TableHeaders.push(item1)
                          
                          // 获取所有日期、时间字段
                          var str1='Time'
                          var str2='Date'
                          if(item1.parameterName!=null&&item1.parameterName.indexOf(str1) !==-1||item1.parameterName!=null&&item1.parameterName.indexOf(str2) !==-1){
                                  this.dateziduanS.push(item1.parameterName)
                          }
                      }
                     
                  })
                 
              }
              this.loading = false;
              
          })
         
         
      }
  },
};
</script>

<style lang="scss" scoped>
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.bodyBox {
  width: 100%;
  height: 100%;
  margin-bottom: 20px;
  // display: flex;
}

.searchIpt {
  width: 70%;
}



.tableBox {
  // width: 71%;
  height: 80vh;
}

.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}

.avatar {
  width: 160px;
  height: 160px;
  display: block;
}

.msgForm .el-form-item {
  margin-bottom: 0px !important;
}


.totalPeople {
  color: #409eff;
  font-weight: 700;
  margin-right: 10px;
}

.numTitle {
  font-weight: bold;
  font-size: 20px;
}
::v-deep .setTableC {
  .el-dialog__body{
      padding-top: 10px;
  }
  .el-dialog__header {
      border-bottom: 1px solid #ddd;
  }
  .Selected_tableH{
      background-color: #f5f8fe;
      border-radius: 5px;
      padding: 10px;
      margin-bottom: 20px;
      border: 1px dashed #ddd;
      .Selected{
          .el-tag{
                  margin-right: 10px;
                  margin-bottom: 10px;
              }
      }
  }
  .SelectBox{
      .work_box{
          background-color: #f5f8fe;
          padding: 10px;
          margin: 15px 0;
          display: inline-flex;
          align-items: center;
      }
      .el-checkbox{
          width: 15%;
          margin-right: 0;
          padding-right: 10px;
          display: inline-flex;
          align-items: center;
          .el-checkbox__label{
              width: 80%;
              overflow: hidden;
              word-wrap: normal;
              white-space: nowrap;
              text-overflow: ellipsis;
          }
      }
      
  }
  
}

  


</style>
